/**
 * @file 	Pair.java
 * 
 * @date 	2/27/2012
 * 
 * @author 	Aaron Alaniz (aaron.a.alaniz@gmail.com)
 * 
 * @brief	This class provides an implementation for a pair helper class 
 * 			that couples objects of differing types.
 * 
 */

public class Pair<S, T> { // represents a pair of elements
	S s;
	T t;
	
	public Pair(S s, T t) {
		this.s = s;
		this.t = t;
	}
	
	public S one() {
		// postcondition: returns the first element of "this" pair
		return s;
	}
	
	public T two() {
		// postcondition: returns the second element of "this" pair
		return t;
	}
	
	public String toString() {
		return "<\"" + s + "\", " + t + ">";
	}
	
	public boolean equals(Object o) { // [5 points]
		// postcondition: returns "true" iff the corresponding elements
		// match identically in "this" and "o"
		
		// Verify object isn't null
		if (o == null) {
			return false;
		}
		
		// Verify object is of the same class
		if (!(o.getClass() == Pair.class)) {
			return false;
		}
		
		Pair p = (Pair) o;
		
		return this.s.equals(p.s) && this.t.equals(p.t);
	}
	
	public int hashCode() { // [5 points]
		// postcondition: satisfies the hash-code contract
		return s.hashCode() + t.hashCode();
	}
}